from time import strftime
import sys

sys.path.append("\\src")
import utils
import player

sys.path.append("..\\src\\cells")
import cells
import cell_ai

sys.path.append("..\\src\\wm")
import wm

sys.path.append("..\\src\\world")
import world
import input

import pygame
from pygame.locals import *

# ------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------

'''Demo:
#Initialize the window manager together with input and graphics
wm = wm._base()

#pallete example 
GRAY_ID = wm.m_GFX.pallete.add_color(100,100,100)

#clear the screen

#a pallete color can be used in two ways you could call on (pallete class).use(colorID)
wm.m_GFX.cls((wm.m_GFX.pallete.use_color(GRAY_ID)))

#or save a color from the pallete and just use that like so
GRAY = wm.m_GFX.pallete.use_color(GRAY_ID) #now the variable gray contains (100,100,100)
wm.m_GFX.cls(GRAY)



#there are two different ways to create a game loop
#(1) Use wm.run() function, this will create an infinite loop that will run as fast as possible
#wm.run()

#(2) Or we can write our own game loop with some timing as well
#wm class has a clock and FPS member that can be used for timing(m_FPS, m_Clock)

result = 0
size = 10

#font test
#add a font, 'add_font' returns an ID that can be saved and used later
Mayday_fontID = wm.m_GFX.add_font('mayday.ttf', 22)
#write text, leaving last argument blank will use pygames default Font(fontID = 0)
wm.m_GFX.write_text((100,100),"Hello World!", 0, (255, 0, 0))
#remove a font, 'rem_font' will also return the size of the font list after removal
#wm.m_GFX.rem_font(Mayday_fontID)

#need to know the dimension of the fps text area
fps_area = wm.m_GFX.write_text((0,0), ("%3.0f"%wm.m_Clock.get_fps()) , 0, (0,255,0),Mayday_fontID)
#default fps limit is 30
wm.m_FPS = 60

#Sprite Demo
wm.m_GFX.m_Color_key = (0,255,255) #Color key to make its background transparent
INF_ID = wm.m_GFX.add_sprite("Infantry.bmp")
wm.m_GFX.draw_sprite(INF_ID, 200,100)
wm.m_GFX.m_Color_key = None #might want to do this so newly added sprites dont get affected
'''
# ----------------------------------------------------------------------------------------------------------------- 
# -----------------------------------------------------------------------------------------------------------------

#Initialize
#Create the logging class, second parameter is DEBUG by default set to INFO to get rid of debug messages":
logger = utils.log_manager("Log.txt")
logger.log.info("Started Logging...")

#Initialize the Window Manager
wm = wm._base(logger)

#initialize player
PLAYER = player.player(wm.m_Input, logger);

#Colors:
CLEAR = (50,50,50)
BLACK = (0,0,0)
PLANET_BROWN = (128,64,64)

wm.m_GFX.cls(CLEAR)

result = 0
size = 100
#build button and some logic associated with it
wm.m_GFX.draw_rectangle(0,500, 100,50, (0,0,255))
wm.m_Input.Area.add_area(0,500,100,50, input.Area_TGAME) #register the blue box as an area of importance

logger.log.info("Starting Main Game Loop")

while result != input.Ev_QUIT:
    
    wm.m_Input.parse()
    
    PLAYER.update()
    if( PLAYER.m_action_selection == player.ACTION_BUILD ):
        wm.m_GFX.draw_rectangle(0,500,100,50, (0,255,0))
    if( PLAYER.m_action == player.ACTION_BUILD ):
        wm.m_GFX.draw_rectangle(wm.m_Input.m_Mousex, wm.m_Input.m_Mousey, 10,10, (50,0,40))
        PLAYER.m_action = -1
        
    wm.m_GFX.flip_buffers()
    
    wm.m_Clock.tick(wm.m_FPS)
    
pygame.display.quit()






















